package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("back/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("show")
    public String showUser(Model model, @RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "9")Integer pageSize){
        PageInfo<User> userPageInfo = userService.showUserPage(pageNum, pageSize);
        model.addAttribute("pageInfo",userPageInfo);
        return "forward:/back/user/show.jsp";
    }
    @RequestMapping("updateStatus")
    public String updateStatus(Integer userId,Integer status){
        User user = userService.showById(userId);
        user.setStatus(status);
        userService.updateUser(user);
        return "redirect:/back/user/show.do";
    }
}
